//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows;


namespace OpenLS.UI.Themes
{
    partial class TabItemResources
    {
        public TabItemResources()
        {
            InitializeComponent();
        }
        void OnTabItemDoubleClick(object sender, MouseButtonEventArgs args)
        {
            DependencyObject o = args.OriginalSource as DependencyObject;
            bool ok = false;
            while (o != null)
            {
                if (o is TabItem)
                {
                    ok = true;
                    break;
                }
                o = VisualTreeHelper.GetParent(o);
            }
            if (!ok)
                return;
            TabItem item = sender as TabItem;
            Ribbon r = item.Parent as Ribbon;
            if (r == null)
                return;
            switch (r.State)
            {
                case RibbonState.Expanded:
                    r.State = RibbonState.Minimized;
                    break;
                default:
                    r.State = RibbonState.Expanded;
                    break;
            }
            args.Handled = true;
        }

        void OnTabItemClick(object sender, MouseButtonEventArgs args)
        {
            TabItem item = sender as TabItem;
            Ribbon r = item.Parent as Ribbon;
            if (r == null)
                return;
            switch (r.State)
            {
                case RibbonState.Expanded:
                    item.IsSelected = true;
                    return;
                case RibbonState.Minimized:
                    if (!item.IsSelected)
                        item.IsSelected = true;
                    r.State = RibbonState.Open;
                    break;
                case RibbonState.Open:
                    if (!item.IsSelected)
                    {
                        item.IsSelected = true;
                    }
                    else
                        r.State = RibbonState.Minimized;
                    break;
                default:
                    throw new NotSupportedException();
            }
        }

    }
}